from appium import webdriver
from appium.webdriver.webdriver import WebDriver

class AndroidClient(object):
    driver : WebDriver
    @classmethod
    def install_app(cls) -> WebDriver:
        caps = {}
        caps['platformName'] = 'Android'
        # 系统版本
        caps['platformVersion'] = '8.1'
        # 手机序列号
        caps['deviceName'] = 'UGW8FEVS4LGUSKQS'
        # 雪球包名
        caps['appPackage'] = 'com.xueqiu.android'
        # 雪球activity名
        caps['appActivity'] = '.view.WelcomeActivityAlias'
        # 美莱包名
        # caps['appPackage'] = 'com.mylike.mall'
        # 美莱activity名
        # caps['appActivity'] = '.activity.LauncherActivity'
        # 使用键盘输入
        caps['unicodeKeyboard'] = 'True'
        # 重置键盘
        caps['resetKeyboard'] = 'True'
        # ['noReset'] = True 不重置 false 重置应用
        caps['noReset'] = 'True'
        # 赋予APP相应的权限
        caps['autoGrantPermissions'] = 'True'
        caps['automationName'] = 'uiautomator2'
        # 连接测试机所在服务器
        cls.driver = webdriver.Remote('http://localhost:4723/wd/hub', caps)
        # 添加隐式等待 10秒
        cls.driver.implicitly_wait(20)
        return cls.driver

    @classmethod
    def restart_app(cls) -> WebDriver:
        caps = {}
        caps['platformName'] = 'Android'
        # 系统版本
        caps['platformVersion'] = '8.1'
        # 手机序列号
        caps['deviceName'] = 'UGW8FEVS4LGUSKQS'
        # 雪球包名
        caps['appPackage'] = 'com.xueqiu.android'
        # 雪球activity名
        caps['appActivity'] = '.view.WelcomeActivityAlias'
        # 美莱包名
        # caps['appPackage'] = 'com.mylike.mall'
        # 美莱activity名
        # caps['appActivity'] = '.activity.LauncherActivity'
        # 使用键盘输入
        caps['unicodeKeyboard'] = 'True'
        # 重置键盘
        caps['resetKeyboard'] = 'True'
        # ['noReset'] = True 不重置 false 重置应用
        caps['noReset'] = 'True'
        # 赋予APP相应的权限
        caps['autoGrantPermissions'] = 'True'
        caps['automationName'] = 'uiautomator2'
        # 连接测试机所在服务器
        cls.driver = webdriver.Remote('http://localhost:4723/wd/hub', caps)
        # 添加隐式等待 10秒
        cls.driver.implicitly_wait(20)

        return cls.driver